<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .header{
            width: 1200px;
            height: 40px;
            background-color: rebeccapurple;
            margin: 30px auto;
        }
        .tab{
            width: 200px;
            text-align: center;
            line-height: 40px;
            margin: 0 20px;
            background-color: royalblue;
            float: left;
        }
        .content{
            width: 1200px;
            height: 500px;
            background-color: rebeccapurple;
            margin: 30px auto;
            border: 20px blueviolet solid;
        }
        .item{
            width: 1200px;
            height: 500px;
            background-color: rgb(223, 216, 230);
            margin: 30px auto;
            display: none;
        }
        .item:nth-child(1){
            display: block;
        }
        .bg{
            background-color: red;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="tab">1</div>
        <div class="tab">2</div>
        <div class="tab">3</div>
    </div>
    <div class="content">
        <div class="item">1111</div>
        <div class="item">2222</div>
        <div class="item">3333</div>
    </div>
</body>
<script>
    let tabs = document.querySelectorAll('.tab');
    let items = document.querySelectorAll(".item");
   for(var i=0;i<tabs.length;i++){
        (function(i){
            tabs[i].onclick= function(){
                for(var j=0;j<tabs.length;j++){
                    tabs[j].classList.remove('bg');
                    items[j].style.display = "none";
                }
                tabs[i].classList.add("bg");
                items[i].style.display = "block";
            }
        })(i)
   }

</script>
</html>